package com.decent.ejfadmin.report.controller;

import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.report.response.EstimateStockSupplyTimeDto;
import com.decent.ejfadmin.report.service.CollectCardStockReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author weicx
 * @date 2018/08/01
 */
@RestController
@Slf4j
@RequestMapping("CollectCardStockReportController")
public class CollectCardStockReportController {
    @Autowired
    private CollectCardStockReportService collectCardStockReportService;

    /**
     * 收卡卡密库存统计
     *
     * @param pageUnit    分页组件
     * @param productType 运营商
     * @param face        面值
     * @return Page
     */
    @RequestMapping("/collectCardStockReportPage")
    public Page collectCardStockReportPage(Page pageUnit, Integer productType, String face) {
        try {
            return collectCardStockReportService.collectCardStockReportPage(pageUnit, productType, face);
        } catch (Exception e) {
            log.warn("收卡卡密库存统计异常:[{}]", e);
            pageUnit.setResultList(new ArrayList<>());
            pageUnit.setTotal(0);
            return pageUnit;
        }
    }

    /**
     * 分页查询收卡库存折扣
     *
     * @param pageUnit    分页组件
     * @param productType 运营商
     * @param face        面值
     * @return Page
     */
    @RequestMapping("/collectCardStockPricePage")
    public Page collectCardStockPricePage(Page pageUnit, Integer productType, String face) {
        try {
            return collectCardStockReportService.collectCardStockPricePage(pageUnit, productType, face);
        } catch (Exception e) {
            log.warn("收卡库存折扣计异常:[{}]", e);
            pageUnit.setResultList(new ArrayList<>());
            pageUnit.setTotal(0);
            return pageUnit;
        }
    }

    /**
     * 预估收卡库存销卡时间
     *
     * @param productType 运营商
     * @param face        面值
     * @param account        会员编号
     * @return
     */
    @RequestMapping("/apiEstimateStockSupplyTime")
    public List<EstimateStockSupplyTimeDto> apiEstimateStockSupplyTime(Integer productType, String face,String account) {
        try {
            return collectCardStockReportService.estimateStockSupplyTime(productType, face,account);
        } catch (Exception e) {
            log.warn("预估收卡库存销卡时间异常: [{}]", e);
            return new ArrayList<>();
        }
    }
}
